#include "MappingEngine.h"
#include "GameObject.h"

GameObject *meshes[100];
int objectCount = 0;

MappingEngine::MappingEngine(LPDIRECT3DDEVICE9 pD3DDevice)
{
	g_pd3dDevice = pD3DDevice;	
  char line[2000];
  ifstream fin("example.txt");
  if (fin.is_open())
  {
    while (! fin.eof() )
    {
		fin.getline(line, 2000);

		char* filename = strtok(line,",");
		
		meshes[objectCount] = new GameObject(g_pd3dDevice,filename,D3DXVECTOR3(0,0,0),D3DXVECTOR3(0,0,0),D3DXVECTOR3(1,1,1));
		objectCount++;
    }
	fin.close();
  }
  else 
  {
	  //TODO Unable to open file
  }
}

MappingEngine::~MappingEngine(void)
{
	for(int i=0; i<objectCount; i++)
	{
		meshes[i]->~GameObject();
	}	
}

void MappingEngine::Render(void)
{	
	for(int i=0; i<objectCount; i++)
	{
		meshes[i]->Render();
	}		
}
